<template>
  <div v-if="workspaceLoaded">
    <slot></slot>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted } from 'vue';
import { emitter, events } from '../../store/eventemitter';
import { workspaceLoadedAtom } from '../../store/jotai';
import { useAtom } from 'jotai-vue';

const [workspaceLoaded, setWorkspaceLoaded] = useAtom(workspaceLoadedAtom);

onMounted(() => {
  const handleWorkspaceLoaded = () => {
    setWorkspaceLoaded(true);
  };

  emitter.on(events.WORKSPACE_LOADED, handleWorkspaceLoaded);

  // Clean up event listener on unmount
  onUnmounted(() => {
    emitter.off(events.WORKSPACE_LOADED, handleWorkspaceLoaded);
  });
});
</script>
